//
//  Extension+UIImageView.swift
//  yktIcve
//
//  Created by 尤增强 on 2019/5/23.
//  Copyright © 2019 zqyou. All rights reserved.
//

import UIKit
import SDWebImage
 extension UIImageView {
    //设置图片sdImg
    func setSDImg(str:String){
        if let path = Bundle.main.path(forResource: "loading", ofType: ".gif"){
            let data = NSData(contentsOfFile: path)
            self.setSDImg(str: str, img:UIImage.sd_animatedGIF(with: data! as Data) )
        }
        else if let image = UIImage(named: "default_slider_img.png"){
            self.setSDImg(str: str, img:image )
        }
    }
    
    //设置图片sdImg
    func setSDImg(str:String,img:UIImage){
        self.isHidden = false
        let urls = str.components(separatedBy: "?")
        self.sd_setImage(with: URL(string: urls[0]), placeholderImage: img)
    }
    
//    func setFLAnimatedSDImg(str:String,img:UIImage){
//        let contentMode = self.contentMode
//        let masksToBounds = self.layer.masksToBounds
//        self.contentMode = .center
//        self.layer.masksToBounds = true
//        let urls = str.components(separatedBy: "?")
//        self.sd_setImage(with: URL(string: urls[0]), placeholderImage: img, options: SDWebImageOptions.refreshCached) { (img, error, cacheType, url) in
//            if img != nil{
//                self.contentMode = contentMode
//                self.layer.masksToBounds = masksToBounds
//            }
//        }
//    }

}
